package threadSynchronization;

import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Author: WanqingLiu
 * @Date: 2023/02/02/15:43
 * 测试 JUC 安全类型的集合
 */
public class TestJUC {
    public static void main(String[] args) throws InterruptedException {
        CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<>();
        for (int i=0; i<10000; i++){
            // 两个线程覆盖了同一个位置
            new Thread(() ->{
                list.add(Thread.currentThread().getName());
            }).start();
        }
        // 让主线程睡一会，保证能执行完
        Thread.sleep(1000);
        System.out.println(Thread.currentThread().getName());

        System.out.println(list.size());
        System.out.println(list.size());
        System.out.println(list.size());
    }
}
